package com.exonline.backstage.controller.student;


import com.exonline.commons.base.IBaseService;
import com.exonline.backstage.entity.Student;
import com.exonline.commons.dao.DaoImpl;
import com.exonline.commons.dao.IDao;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class StudentService implements IBaseService<Student> {
    IDao<Student> studentDao = new DaoImpl<Student>();
    @Override
    public List<Student> queryAll(int pageSize, int pageNo) throws SQLException {
        return studentDao.queryWithPagingAndConditions("SELECT * FROM student",null,pageNo,pageSize,new BeanListHandler<>(Student.class));
    }

    @Override
    public Student queryOne(String id) throws SQLException {
        return   studentDao.queryForObject("select * from user where id = ?", new BeanHandler<>(Student.class), id);
    }

    @Override
    public void add(Object...paras) throws SQLException {
        studentDao.updateWithTransaction("INSERT INTO student(id,sname,phone,email,password,status) VALUES(?,?,?,?,?,?)",paras);
    }

    @Override
    public void update(Object...paras) throws SQLException {
        studentDao.updateWithTransaction("UPDATE student SET sname = ?,phone=?,password=? WHERE id = ?",paras);
    }

    @Override
    public void deleteById(String id) throws SQLException {
        studentDao.updateWithTransaction(" DELETE FROM student WHERE id = ?",id);
    }
}
